const qs = ele => document.querySelector(ele)
axios.defaults.baseURL = 'http://124.223.14.236:3001/api'
async function fn() {
    // 省
    const { data: { data: provinceData } } = await axios.get('/city/province')
    console.log(provinceData);
    const provinceStr = provinceData.map(item => `<option value="${item.province}">${item.name}</option>`)
    qs('#province').innerHTML = `<option value="">请选择省份</option>` + provinceStr
    qs('#province').value = '34'
    // 市
    const { data: { data: cityData } } = await axios.get('/city/city', { params: { provinceCode: '34' } })
    console.log(cityData);
    const cityStr = cityData.map(item => `<option value="${item.city}">${item.name}</option>`)
    qs('#city').innerHTML = `<option value="">请选择城市</option>` + cityStr
    qs('#city').value = '01'
    // 县
    const { data: { data: areaData } } = await axios.get('/city/area', {
        params: {
            provinceCode: '34',
            cityCode: '01'
        }
    })
    console.log(areaData);
    const areaStr = areaData.map(item => `<option value="${item.area}">${item.name}</option>`)
    qs('#county').innerHTML = `<option value="">请选择区县</option>` + areaStr
    qs('#county').value = '02'
}
fn()
qs('#province').addEventListener('change', async function () {
    // console.log(1);  
    const { data: { data: cityData } } = await axios.get('/city/city', { params: { provinceCode: this.value } })
    console.log(cityData);
    const cityStr = cityData.map(item => `<option value="${item.city}">${item.name}</option>`)
    qs('#city').innerHTML = `<option value="">请选择城市</option>` + cityStr
    qs('#county').innerHTML = '<option value="">请选择区县</option>'
})
qs('#city').addEventListener('change', async function () {
    const { data: { data: areaData } } = await axios.get('/city/area', {
        params: {
            provinceCode: qs('#province').value,
            cityCode: this.value
        }
    })
    console.log(areaData);
    const areaStr = areaData.map(item => `<option value="${item.area}">${item.name}</option>`)
    qs('#county').innerHTML = `<option value="">请选择区县</option>` + areaStr
})